package com.netease.entity;

import com.netease.utils.SortByLengthComparator;
import com.netease.utils.StringUtils;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;
import lombok.experimental.Accessors;

import java.util.ArrayList;
import java.util.Collections;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Accessors(chain = true)
public class Word {
    //初始中文名称
    private String initialName = "";
    //词根中文名称
    private String name = "";
    //开始下标
    private Integer startOffset = 0;
    //结束下标
    private Integer endOffset = 0;
    //英文名称
    private String engName = "";
    //英文缩写
    private String engAbbreviation = "";
    //词频
    private Integer wordFrequency = 0;
    //业务板块
    private String bsinssPlate;

    public void engAbbreviationSort(){
        StringBuilder sb = new StringBuilder();

        String[] splits = this.engAbbreviation.split("\\|");

        ArrayList<String> arrayList = new ArrayList<>();

        for (int i = 0; i < splits.length; i++) {
            String word = splits[i].toLowerCase();
            if (word.contains(" ")){
                arrayList.add(StringUtils.sortWord(word));
            }else{
//                if (word.length() > 5){
////                    arrayList.add(word.substring(0,5));
////                }
                arrayList.add(word.replaceAll("-","_"));
            }

        }

        //对ArrayList元素进行排序
        Collections.sort(arrayList, new SortByLengthComparator());

        //拼接字符串
        for (int i1 = 0; i1 < arrayList.size(); i1++) {
            sb.append(arrayList.get(i1));
            if (i1 < arrayList.size() - 1) {
                sb.append("|");
            }
        }

        this.engAbbreviation = sb.toString();
    }
}
